package com.skillworld.webapp.model.award;

import java.util.Locale;
import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyColumn;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="Award")
public class Award 
{
    
	private Long awardId;
	private String image;
	private Map<Locale,AwardDetails> localizedDetails;
		
	protected Award() 
	{ 

	}

	
    @SequenceGenerator(name="AwardIdGenerator",sequenceName="AwardSeq")
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO,generator="AwardIdGenerator")
	@Column(name="idAward")
	public Long getAwardId() {
		return awardId;
	}

	public void setAwardId(Long awardId) {
		this.awardId = awardId;
	}

	@Column(name="img")
    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    @ElementCollection(fetch=FetchType.EAGER)
    @CollectionTable(name="AwardDetails",
                     joinColumns=@JoinColumn(name="idAward"))
    @MapKeyColumn(name="locale")
    protected Map<Locale, AwardDetails> getLocalizedDetails() {
        return localizedDetails;
    }

    protected void setLocalizedDetails(Map<Locale, AwardDetails> localizedDetails) {
        this.localizedDetails = localizedDetails;
    }
    
    @Transient
    public AwardDetails getDetails(Locale locale)
    {
        return getLocalizedDetails().get(locale);
    }
    
    @Transient
    public String getInfo(Locale locale)
    {
        return getDetails(locale).getInfo();
    }
	
}
